<template>
  <div id="app">
    <router-view/>
  </div>
</template>
<script>
import {mapActions, mapState} from 'vuex'
export default {
  data(){
    return{

    }
  },
  computed:{
    ...mapState(["systemToken"]),
  },
  mounted() {
    window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
    window.addEventListener('unload', e => this.unloadHandler(e))
    console.log('env',process.env)
  },
  destroyed() {
    window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
    window.removeEventListener('unload', e => this.unloadHandler(e))
  },

  methods:{
    ...mapActions(["SavePath","Logout"]),
    beforeunloadHandler(){
      this._beforeUnload_time=new Date().getTime();
    },
    unloadHandler(e){
          this._gap_time=new Date().getTime()-this._beforeUnload_time;
          //判断是窗口关闭还是刷新
          if(this._gap_time<=5){
            this.Logout()
            this.SavePath('')
          }
        },
    },

  watch:{
    $route:{
      handler(val,oldval){
        // console.log(val);//新路由信息
        // console.log(oldval);//老路由信息
        this.SavePath(val.path)
      },
      // 深度观察监听
      deep: true
    },
    // '$store.state.systemToken':{
    //   deep: true,
    //   handler(val,oldval){
    //     console.log(val,oldval);//新路由信息
    //   },
    // }
  }
}
</script>

<style lang="less">
// 全局样式
html,body,#app{
  // 需要将height设为auto，才能监听高度变化
  height: auto;
  margin: 0;
  padding: 0;
  width:100%;
  overflow-x:hidden;
  overflow: scroll;
}
// 全局样式
@import "./utils/styles/base.less";
</style>
